package com.zhss.dfs.server;

/**
 * DataNode启动类
 *
 * @author zhonghuashishan
 */
public class DataNode {

    /**
     * 负责跟一组NameNode通信的组件
     */
    private NameNodeServiceActor nameNodeServiceActor;


    /**
     * 初始化DataNode
     */
    private void initialize() {
        try {
            this.nameNodeServiceActor = new NameNodeServiceActor(DataNodeConfig.NAME_NODE_IP,DataNodeConfig.NAME_NODE_PORT);
            boolean exists = this.nameNodeServiceActor.register();
            // 进行心跳检测
            this.nameNodeServiceActor.heartBeat();
            // nameNode 不存在进行全量上报
            if (!exists) {
                nameNodeServiceActor.reportCompleteFileInfo();
            }
            NioFileServer nioFileServer = new NioFileServer(this.nameNodeServiceActor);
            nioFileServer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 运行DataNode
     */
    private void run() {
        try {
           while (true) {
               Thread.sleep(1000);
           }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        DataNode datanode = new DataNode();
        datanode.initialize();
        datanode.run();
    }

}
